import logging
import app
from django.core.cache import cache
from django.http import HttpRequest
from django.core.serializers.json import DjangoJSONEncoder

class logger():
    def __init__(self, file):
        self.__myLogger = logging.getLogger(file)

    def debug(self, msg):
        self.__myLogger.debug(msg)

    def info(self, msg):
        self.__myLogger.info(msg)

def get_root_path():
    import os
    # dir = module_dir(app)

    # 假设你有一个名为'myapp'的应用
    #app_module = get_module('myapp')
    app_dir = os.path.dirname(os.path.dirname(app.__file__))
    return app_dir

# 获取项目根目录
root_path = get_root_path()

def response(data = None, code = 200, msg = "success"):
    from django.http import JsonResponse
    resData = {'code': code, 'message': msg, 'data': data}
    return JsonResponse(resData, safe=False, encoder=DjangoJSONEncoder)

def url(path:str):
    scheme = cache.get('http_scheme')
    host = cache.get('http_host')
    path = path.lstrip("/")
    return scheme + '://' + host + '/' + path


